package com.fruit.web.vo.genl;

import java.util.List;




import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.fruit.service.ICategoryService;
import com.fruit.utils.MessageFactory;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.web.bo.impl.Category;
import com.fruit.web.constant.EjdConstants;
import com.fruit.web.constant.SpringBeanConstants;

@ManagedBean(name="existCategory")
@SessionScoped
public class ExistCategoryBean implements java.io.Serializable {

	private SelectItem[] categoryItems;

	
	public SelectItem[] getCategoryItems() {
		return categoryItems;
	}


	public void setCategoryItems(SelectItem[] categoryItems) {
		this.categoryItems = categoryItems;
	}


	public ExistCategoryBean() {
		
		ICategoryService<Category,Long> categoryService = (ICategoryService<Category,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.CATEGORY_SERVICE_BEAN_NAME);
		categoryService.setEntityClass(Category.class);
		categoryService.setPKClass(Long.class);
		List<Category> categorys = categoryService.getAll("serialNumber",true);
		SelectItem[] tempCategoryItems = new SelectItem[categorys.size()];
		//set select default 
		if (null != categorys && !(categorys.isEmpty())) {
			for (int i=0; i< tempCategoryItems.length; i++) {
				Category category = (Category) categorys.get(i);
				String categoryNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,category.getCategoryName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempCategoryItems[i] = new SelectItem(category.getCategoryCode(),categoryNameN18);
			}
		}
		this.setCategoryItems(tempCategoryItems);
	}
}
